package com.ex02.ylw;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;

/**
 * 这里是Request的封装类，里面有一个Request对象，提供给别的类，
 * 防止原生的Request类里面的部分方法被调用，因为Request里面的parse方法是公用的,
 * 一般ServletProcess类里面穿的request参数就是这个封装类，就是为了防止原生里面的部分方法被使用，
 * 然而这个类里面的方法都是调用原生类里面的方法
 *
 * Created by yangliwei on 2017/7/23.
 */
public class RequestWrapper implements ServletRequest{
    Request request ;

    public RequestWrapper(Request request) {
        this.request = request;
    }


    @Override
    public Object getAttribute(String s) {
        return this.request.getAttribute(s);
    }

    @Override
    public Enumeration getAttributeNames() {
        return this.request.getAttributeNames();
    }

    @Override
    public String getCharacterEncoding() {
        return this.request.getCharacterEncoding();
    }

    @Override
    public void setCharacterEncoding(String s) throws UnsupportedEncodingException {
            this.request.setCharacterEncoding(s);
    }

    @Override
    public int getContentLength() {
        return this.request.getContentLength();
    }

    @Override
    public String getContentType() {
        return this.request.getContentType();
    }

    @Override
    public ServletInputStream getInputStream() throws IOException {
        return this.request.getInputStream();
    }

    @Override
    public String getParameter(String s) {
        return this.request.getParameter(s);
    }

    @Override
    public Enumeration getParameterNames() {
        return this.request.getParameterNames();
    }

    @Override
    public String[] getParameterValues(String s) {
        return this.request.getParameterValues(s);
    }

    @Override
    public Map getParameterMap() {
        return this.request.getParameterMap();
    }

    @Override
    public String getProtocol() {
        return this.request.getProtocol();
    }

    @Override
    public String getScheme() {
        return this.request.getScheme();
    }

    @Override
    public String getServerName() {
        return this.request.getServerName();
    }

    @Override
    public int getServerPort() {
        return this.request.getServerPort();
    }

    @Override
    public BufferedReader getReader() throws IOException {
        return this.request.getReader();
    }

    @Override
    public String getRemoteAddr() {
        return this.request.getRemoteAddr();
    }

    @Override
    public String getRemoteHost() {
        return this.request.getRemoteHost();
    }

    @Override
    public void setAttribute(String s, Object o) {
        this.request.setAttribute(s,o);
    }

    @Override
    public void removeAttribute(String s) {
        this.request.removeAttribute(s);
    }

    @Override
    public Locale getLocale() {
        return this.request.getLocale();
    }

    @Override
    public Enumeration getLocales() {
        return this.request.getLocales();
    }

    @Override
    public boolean isSecure() {
        return this.request.isSecure();
    }

    @Override
    public RequestDispatcher getRequestDispatcher(String s) {
        return this.request.getRequestDispatcher(s);
    }

    @Override
    public String getRealPath(String s) {
        return this.request.getRealPath(s);
    }
}
